package servlet;

import dao.Db;
import model.User;

import javax.servlet.GenericServlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/update")
public class updateOne extends GenericServlet {
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        //设置编码
        servletRequest.setCharacterEncoding("UTF-8");
        servletResponse.setContentType("text/html;charset=UTF-8");
         Db db = new Db();
        //收参
         String id = servletRequest.getParameter("id");
        User user = db.getOneData(id);
        //服务器渲染表单
        PrintWriter writer = servletResponse.getWriter();
        writer.write("<!DOCTYPE html>");
        writer.write("<html>");
        writer.write("<head><meta charset='utf-8'><title>用户信息更新</title></head>");

        writer.write("<body>");

        writer.write("<form action='/javaWebStudy2025_war_exploded/updateOk'>");
        writer.write("<input type='hidden' value='"+user.getId()+"' name='id'><br>");
        writer.write("<input type='text' value='"+user.getUsername()+"' name='username'><br>");
        writer.write("<input type='text' value='"+user.getPassword()+"' name='password'><br>");
        writer.write("<input type='text' value='"+user.getBirthday()+"' name='birthday'><br>");
        writer.write("<input type='submit' value='提交'><br>");
        writer.write("</form>");
        writer.write("</body>");
        writer.write("</html>");

    }
}

